﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Account
{
  
    private string accountId;
    private decimal balance;

 
    public string AccountId { get => accountId; set => accountId = value; }
    public virtual decimal Balance { get => balance; protected set => balance = value; }
    public AccountType Type { get; protected set; }

  
    private TransactionRecord[] transactions = new TransactionRecord[50];
    private int recordCount = 0;
    public TransactionRecord this[int index] => transactions[index];

    public Account(string id, decimal initBalance)
    {
        accountId = id;
        balance = initBalance;
        Type = AccountType.Saving;
    }

    public virtual void Deposit(decimal amount)
    {
        Balance += amount;
        AddTransaction(amount, "存款");
    }

 
    public virtual void Withdraw(decimal amount)
    {
        if (amount > Balance)
            throw new InvalidOperationException("余额不足！");
        Balance -= amount;
        AddTransaction(-amount, "取款");
    }

    protected void AddTransaction(decimal amount, string description)
    {
        transactions[recordCount++] = new TransactionRecord
        {
            Time = DateTime.Now,
            Amount = amount,
            Description = description
        };
    }

    public override string ToString()
    {
        return $"账户号：{AccountId}，余额：{Balance:C}，类型：{Type}";
    }
}

